package com.boang.method;

import java.util.Comparator;
import java.util.function.Consumer;
import java.util.function.Supplier;

/*
    @author:sa
    @date:2024/12/2 14:00
*/
public class MethodDemo {
    public static void main(String[] args) {
        m1();
        m2();
        Supplier<Student> supplier = new Supplier<>() {
            @Override
            public Student get() {
                return new Student();
            }
        };
        supplier=()->new Student();
        supplier=Student::new;
        Student student=supplier.get();
        System.out.println(supplier.get());
    }

    private static void m2() {
        Comparator<Integer> comparator = new Comparator<>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return (o1-o2);
            }
        };
        int i = comparator.compare(2, 1);
        System.out.println(i);
        comparator=(o1, o2) ->o1-o2;
        i=comparator.compare(1, 2);
        comparator=Integer::compare;
    }

    private static void m1() {
        Consumer<String> consumer = new Consumer<>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        };
        consumer.accept("下午茶");
        consumer=s-> System.out.println(s);
        consumer.accept("睡一觉");
        consumer=System.out::println;
        consumer.accept("写代码");
    }
}